TOP

Title Case Function for LibreOffice Calc

TITLECASE() Description

The function TITLECASE() is designed to convert existing text into heading format and returns a set of words in the form: "Function for Title Case" .

The Title Case function code replaces separators such as hyphens and underscores with spaces, converts all words to uppercase, and converts conjunctions to lowercase.

Title Case can be useful for case correction in news headlines, site article titles, or YouTube video titles.

TITLECASE() is similar to the standard PROPER() function, except that conjunctions are not capitalized.


StarBASIC Code for TITLECASE()

Here is the macro code to create a custom function that can display text as titles (Title Case) in LibreOffice Calc.

Open the menu Tools - Macros - Edit Macros..., select Module1 and copy the following text into the module:

Function TitleCase(ByVal str As String) As String
  'moonexcel.com.ua
  Dim words As Variant
  Dim FCalc As Object
    
  FCalc = CreateUnoService("com.sun.star.sheet.FunctionAccess")  
    
  oddWordsLat = "A|An|And|As|At|But|By|En|For|If|In|Is|Of|On|Or|The|To|Vs|Via"
  oddWordsCyr = "І|Як|На|Але|Для|Якщо|В|Чи|До|Через|Та|Від|Під|Над|И|Как|Но|То|Или|От|Под|К"  
  words = Split(oddWordsLat + "|" + oddWordsCyr,"|") 
  
  str = FCalc.callFunction("PROPER", Array(str))  
  
  For i = LBound(words) To UBound(words)  
    pattern = "(?!^)\b" + words(i) + "\b"
    replacement = LCase(words(i))
    
    str = FCalc.callFunction("REGEX", Array(str,pattern,replacement,"g"))
  Next i
    
  TitleCase = str
End Function

Then close Macro Editor, return to LibreOffice Calc and use our new function in any cell.

Using the extension

You can also use the feature TITLECASE() by installing the free extension YouLibreCalc.oxt or its full-featured version YLC_Utilities.oxt .

After that, this function will be available in all files that will be opened in LibreOffice Calc.